﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ChuongtrinhTracnghiem.View
{
    public partial class FormCauhoi : Form
    {
        public FormCauhoi()
        {
            InitializeComponent();
        }

        DataTable ds = new DataTable();
        int i = 0;
        int themsua = 0;

        public void Display_Tooltip1()
        {
            toolStripButton_Them.Enabled = true;
            toolStripButton_Sua.Enabled = true;
            toolStripButton_Lưu.Enabled = false;
            toolStripButton_Boqua.Enabled = false;
            toolStripButton_Xoa.Enabled = true;
            toolStripButton_Tim.Enabled = true;
            toolStripButton_Dau.Enabled = true;
            toolStripButton_Toi.Enabled = true;
            toolStripButton_Lui.Enabled = true;
            toolStripButton_Cuoi.Enabled = true;
            toolStripButton_Thoat.Enabled = true;

        }
        public void Display_Tooltip2()
        {
            toolStripButton_Them.Enabled = false;
            toolStripButton_Sua.Enabled = false;
            toolStripButton_Lưu.Enabled = true;
            toolStripButton_Boqua.Enabled = true;
            toolStripButton_Xoa.Enabled = false;
            toolStripButton_Tim.Enabled = false;
            toolStripButton_Dau.Enabled = false;
            toolStripButton_Toi.Enabled = false;
            toolStripButton_Lui.Enabled = false;
            toolStripButton_Cuoi.Enabled = false;
            toolStripButton_Thoat.Enabled = false;
        }

        public void Display()
        {
            string s = "select * from TblCauhoi";
            Model.Laydulieu dl = new Model.Laydulieu();
            ds = dl.Dulieu(s, "TblCauhoi");
            DataColumn[] dt = new DataColumn[1];
            dt[0] = ds.Columns[0];
            ds.PrimaryKey = dt; //Tạo khóa 
            this.textBox_Cauthu.Text = (i+1).ToString();
            this.richTextBox_Cauhoi.Text = ds.Rows[i]["Cauhoi"].ToString();
            this.textBox_DapanA.Text = ds.Rows[i]["DapanA"].ToString();
            this.textBox_DapanB.Text = ds.Rows[i]["DapanB"].ToString();
            this.textBox_DapanC.Text = ds.Rows[i]["DapanC"].ToString();
            this.textBox_DapanD.Text = ds.Rows[i]["DapanD"].ToString();
            this.comboBox_Dapandung.Text = ds.Rows[i]["Caudung"].ToString();
            Model.Ketnoi.Boketnoi();
            Display_Tooltip1();
        }
        private void FormCauhoi_Load(object sender, EventArgs e)
        {
            Display();

        }

        private void toolStripButton_Dau_Click(object sender, EventArgs e)
        {
            i = 0;
            Display();
        }

        private void toolStripButton_Toi_Click(object sender, EventArgs e)
        {
            if (i < ds.Rows.Count - 1)
            {
                i++;
                Display();
            }

        }

        private void toolStripButton_Lui_Click(object sender, EventArgs e)
        {
            if (i > 0)
            {
                i--;
                Display();
            }
  
        }

        private void toolStripButton_Cuoi_Click(object sender, EventArgs e)
        {
            i = ds.Rows.Count - 1;
            Display();

        }

        private void toolStripButton_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void toolStripButton_Them_Click(object sender, EventArgs e)
        {
            Display_Tooltip2();
            textBox_Cauthu.Text = "";
            textBox_Cauthu.Enabled = false;
            richTextBox_Cauhoi.Text = "";
            textBox_DapanA.Text = "";
            textBox_DapanB.Text = "";
            textBox_DapanC.Text = "";
            textBox_DapanD.Text = "";
            comboBox_Dapandung.Items.Clear();
            comboBox_Dapandung.Items.Add("A");
            comboBox_Dapandung.Items.Add("B");
            comboBox_Dapandung.Items.Add("C");
            comboBox_Dapandung.Items.Add("D");

        }

        private void toolStripButton_Boqua_Click(object sender, EventArgs e)
        {
            Display();
            textBox_Cauthu.Enabled = false;

        }


    }
}
